<?php

namespace App\Models\Car;

use App\Models\Constant\CarConstant;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Models\Common\CommonModel;
class Order extends CommonModel
{
    use HasFactory;

    protected $table = 'order';

    protected $appends = ['status_name'];

    public function getStatusNameAttribute(){
        return CarConstant::OrderStatus[$this->status]??'未知';
    }

    public function getLst(array $conditions = []){
        $records = parent::getLst($conditions); // TODO: Change the autogenerated stub
        if(!empty($conditions['car_id'])){
            $sql = "find_in_set(".$conditions['car_id'].",car_ids)";
            $records = $records->whereRaw($sql);
        }
        if(!empty($conditions['rent_unit_id'])){
            $records = $records->where('rent_unit_id',$conditions['rent_unit_id']);
        }

        return $records;
    }


}
